package com.zhika.zishi.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.zhika.zishi.R;
import com.zhika.zishi.customview.TitleView;
import com.zhika.zishi.customview.customlayout.FlowLayout;
import com.zhika.zishi.interfaces.TitleInterface;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by shi-02 on 2015/4/17.
 * 修改频道
 */
public class EditChannelActivity extends BaseActivity {

    private TitleView titleView;

    private FlowLayout flowLayout;

    private String[] strs = new String[]{
            "频道","频道频道",
            "频道频道频道","频道频道频道频道",
            "频道频道频道频道频道","频道频道频道频道频道频道频道频道频道频道",
            "频道","频道频道",
            "频道","频道频道",
            "频道","频道频道",
            "频道","频道频道",
            "频道","频道频道频道频道频道频道",
            "频道频道频道","频道频道"
    };

    private boolean bArray[] = new boolean[18];

    private TextView textArray[] = new TextView[18];

    private HashMap<TextView,Boolean> bMap = new HashMap<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_channel_layout);

        initView();

    }

    private void initView(){
        titleView = (TitleView) findViewById(R.id.edit_channel_title_view);
        titleView.setLeftButtonText("返回");
        titleView.setMiddleRowText("修改频道");
        titleView.setRightButtonText("确定");
        titleView.setTitleViewInterface(new TitleInterface() {
            @Override
            public void leftTitleListener() {
                finish();
            }

            @Override
            public void middleTitleListener() {

            }

            @Override
            public void rightTitleListener() {
                Toast.makeText(EditChannelActivity.this,"确定按钮",Toast.LENGTH_SHORT).show();
                finish();
            }
        });


        flowLayout = (FlowLayout) findViewById(R.id.edit_channel_flow_layout);

        LayoutInflater layoutInflater = LayoutInflater.from(EditChannelActivity.this);


        for ( int i = 0;i<18;i++){
            final TextView textView = (TextView) layoutInflater.inflate(R.layout.my_text_view,flowLayout,false);
            textView.setText(strs[i]);
            textArray[i] = textView;
//            bArray[i] = false;
            bMap.put(textArray[i],false);
            flowLayout.addView(textView);
        }

        for (int k=0;k<18;k++){
            textArray[k].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (bMap.get((TextView) v)){
                        v.setBackground(getResources().getDrawable(R.drawable.text_3_shape));
                        bMap.put((TextView) v,false);
                    }else {
                        v.setBackground(getResources().getDrawable(R.drawable.text_4_shape));
                        bMap.put((TextView) v,true);
                    }
                }
            });
        }

        textArray[3].setBackground(getResources().getDrawable(R.drawable.text_4_shape));
        textArray[5].setBackground(getResources().getDrawable(R.drawable.text_4_shape));
        textArray[7].setBackground(getResources().getDrawable(R.drawable.text_4_shape));
        textArray[10].setBackground(getResources().getDrawable(R.drawable.text_4_shape));

        bMap.put(textArray[3],true);
        bMap.put(textArray[5],true);
        bMap.put(textArray[7],true);
        bMap.put(textArray[10],true);

    }
}
